﻿// Apache-2.0 License
// Copyright (c) 2021-2022 朱飞龙
// 电话/微信：18706708563  QQ群：136192142

using Furion.Logging.Extensions;
using Furion.Schedule;
using Furion.TaskQueue;
using Radius.NET.Interface.Kingdee.Service.BasicInfoModule;

namespace Radius.NET.Interface.Job;

//[JobDetail("sync_kingdee_misvendorlist", Description = "同步供应商档案", GroupName = "default", Concurrent = false)]
//[Daily(TriggerId = "trigger_sync_kingdee_misvendorlist", Description = "同步金蝶资料")]
//[PeriodSeconds(10, TriggerId = "trigger_sync_kingdee_misvendorlist", Description = "同步供应商档案", MaxNumberOfRuns = 1, RunOnStart = true)]
public class SyncKindeeMisVendorListJob
{
    private readonly IServiceProvider _serviceProvider;

    public SyncKindeeMisVendorListJob(IServiceProvider serviceProvider)
    {
        _serviceProvider = serviceProvider;
    }
    public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
    {
        await TaskQueued.EnqueueAsync(async (provider, token) =>
        {
            using var serviceScope = _serviceProvider.CreateScope();
            var bascInfoService = serviceScope.ServiceProvider.GetService<MisVendorService>();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("【" + DateTime.Now + "】同步供应商档案");
            ("【" + DateTime.Now + "】同步供应商档案").LogInformation();

            //同步一周之内的数据
            string date = context.OccurrenceTime.AddDays(-7).ToString("yyyy-MM-dd");

            //同步供应商档案
            await bascInfoService.SyncMisVendorList(39, date);
        });
    }
}
